home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / external / sharelib / simple_c2f.pro < prev    next >
Encoding:
Text File  |  1997-07-08  |  3.3 KB  |  131 lines

  1. ;;    $Id: simple_c2f.pro,v 1.2 1995/08/02 17:01:04 kirk Exp $
  2. ;;
  3. ;; PURPOSE:
  4. ;;    This IDL procedure is used to show how to call an external 
  5. ;;    C wrapper function that then calls a Fortran routine.
  6. ;;    
  7. ;;============================================================================
  8.  
  9.     PRO SIMPLE_C2F
  10. ;;
  11. ;;    Determine what operating system we are on and set-up the proper
  12. ;;    library file extensions.
  13.  
  14.         CASE !VERSION.ARCH OF
  15.  
  16.            'sparc'      :BEGIN
  17.  
  18.                 LIB_EXT         = 'so'
  19.  
  20. ;;              Determine if the OS is Solaris
  21.  
  22.                 aa = findfile('/proc',COUNT = CNT)
  23.                 IF(CNT eq 0)THEN                $
  24.                    ENTRY_PREFIX = '_'           $
  25.                 ELSE                            $
  26.                    ENTRY_PREFIX = ''
  27.  
  28.             END
  29.  
  30.            'hp_pa'      :BEGIN
  31.  
  32.                 LIB_EXT         = 'sl'
  33.                 ENTRY_PREFIX    = ''
  34.  
  35.             END
  36.  
  37.            'hp9000s300' :BEGIN
  38.  
  39.                 LIB_EXT         = 'sl'
  40.                 ENTRY_PREFIX    = '_'
  41.  
  42.             END
  43.  
  44.            'ibmr2'      :BEGIN
  45.  
  46.                 LIB_EXT         = 'lib'
  47.                 ENTRY_PREFIX    = ''
  48.  
  49.             END
  50.  
  51.             'alpha'     :BEGIN        ;Dec OSF1
  52.  
  53.                LIB_EXT = 'so'
  54.                ENTRY_PREFIX = ''
  55.  
  56.             END
  57.  
  58.             ELSE        :BEGIN
  59.  
  60.                 MESSAGE,"CASE ERROR: User must add correct entry name", $
  61.                         /CONTINUE
  62.  
  63.                 RETURN
  64.  
  65.             END
  66.         ENDCASE
  67.  
  68. ;;
  69. ;;     Some operating systems require that you use full path names. Get
  70. ;;    the current working directory.
  71.  
  72.     CD, '.', CURRENT=PWD
  73.     PWD= PWD+'/'
  74.  
  75. ;;    Determine if the library file has been build or not. If it 
  76. ;;    hasn't write a message and return.
  77.  
  78.     FILENAME = findfile(PWD+'simple_c2f.'+LIB_EXT, COUNT= CNT)
  79.  
  80.     IF(CNT eq 0)THEN BEGIN
  81.  
  82.       MESSAGE,"The library file, "+PWD+"simple_c2f."+LIB_EXT+ $
  83.         ", is not present. The library file must be built.",/CONTINUE
  84.  
  85.       RETURN
  86.  
  87.     ENDIF
  88.  
  89. ;;    Set up some variables to pass into the test routines
  90.  
  91.     BYTE_VAR        = 2B
  92.     SHORT_VAR        = 3
  93.     LONG_VAR        = 4L
  94.     FLOAT_VAR        = 5.0
  95.     DOUBLE_VAR        = 6D0
  96.     STRING_VAR        = "Seven"
  97.  
  98. ;;    Make the call to the C wrapper via the CALL_EXTERNAL function.
  99.  
  100.     RESULT = call_external(PWD+'simple_c2f.'+LIB_EXT,        $
  101.             ENTRY_PREFIX+'simple_c2f',            $
  102.             BYTE_VAR, SHORT_VAR, LONG_VAR, FLOAT_VAR,       $
  103.                         DOUBLE_VAR, STRING_VAR, /S_VALUE )
  104.  
  105. ;;    Print the results of the function.
  106.  
  107.         PRINT,""
  108.         PRINT,"====================================================="
  109.         PRINT,"Inside IDL: Results of C/Fortran function simple_c2f."
  110.         PRINT,"            Simple variables are squared in the Fortran function"
  111.         PRINT,""
  112.         PRINT,"Results:"
  113.         PRINT,"         Squared BYTE Variable:          ", BYTE_VAR,    $
  114.         FORMAT="(/A,I6)"
  115.         PRINT,"         Squared INT Variable:           ", SHORT_VAR,   $
  116.         FORMAT="(A,I6)"
  117.         PRINT,"         Squared LONG Variable:          ", LONG_VAR,    $
  118.         FORMAT="(A,I6)"
  119.         PRINT,"         Squared FLOAT Variable:         ", FLOAT_VAR,   $
  120.         FORMAT="(A,F6.1)"
  121.         PRINT,"         Squared DOUBLE Variable:        ", DOUBLE_VAR,  $
  122.         FORMAT="(A,F6.1)"
  123.         PRINT,"         Squared STRING Variable:        ", RESULT, $
  124.         FORMAT="(A,A10)"
  125.         PRINT,""
  126.         PRINT,"====================================================="
  127.  
  128. ;;    Thats it.
  129.  
  130.     END
  131.